"ddd"
from selenium.webdriver.common.action_chains import ActionChains
from selenium import webdriver
import time
"""
1，鼠标事件
ActionChains(driver):
    driver： webdriver实例执行用户操作
    ActionChains：ActionChains用于生产用户的行为，所有的行为都存储在ActionChains对象上，
    再通过perform()执行所有ActionChains中存储的行为。


"""
#实例化浏览器驱动
driver = webdriver.Chrome()
#窗口最大话
driver.maximize_window()
#打开百度
driver.get("http://www.baidu.com")
# driver.find_element_by_id('kw').click()
driver.find_element_by_id('kw').send_keys("道长")
# driver.find_element_by_id('su').click()

#右击
# ele = driver.find_element_by_id('kw')
# ActionChains(driver).context_click(ele).perform()
#双击
# ele = driver.find_element_by_id('kw')
# ActionChains(driver).double_click(ele).perform()
#鼠标悬浮在一个元素上
# ele = driver.find_element_by_id('kw')
# ActionChains(driver).move_to_element(ele).perform()
#按下鼠标左键在一个元素上不松开
# ele = driver.find_element_by_id('kw')
# ActionChains(driver).click_and_hold(ele).perform()

# searchButtonJS = "document.getElementById('su').click()"
# driver.execute_script(searchButtonJS)

#1,返回js元素的value值
# value = driver.execute_script("return document.getElementById('su').value")
# print("ddd",value)
# 2.#修改的值，并返回
value = driver.execute_script("return document.getElementById('su').value='h何卜强'")
print("ddd",value)
# 3.使用js定位元素
# document.getElementById(“kw”)
# document.getElementsByName("")
# document.getElementsByClassName("")
# document.getElementsByTagName("")
searchButtonJS = "document.getElementById('su').click()"
driver.execute_script(searchButtonJS)

# 4.页面滚动
# 滚动到顶部
# document.documentElement.scrollTop=0
# 滚动到底部
# document.documentElement.scrollTop=10000
time.sleep(3)
dibu = "return document.documentElement.scrollTop=10000"
driver.execute_script(dibu)
time.sleep(3)
dingbu = "return document.documentElement.scrollTop=0"
driver.execute_script(dingbu)